<?php
namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;

class ELEVENUSER extends NotORM
{

    protected function getTableName($id)
    {
        return 'eleven_user';
    }

    public function findByUid($uid)
    {
        $data = $this->getORM()->where(['uid' => $uid])->where(['new_gift' => 0])->fetchOne();
        return $data;
    }

    public function checkGift($uid)
    {
        $data = $this->getORM()->where(['uid' => $uid])->fetchOne();
        return $data;
    }

    public function getlist($uid = 0,$p) {
        $data = $this->getORM()
            ->limit(($p-1)*10, 10)
            ->where("inviterid = '$uid'")
            ->where("uid != '0'")
            ->order('id desc')
            ->fetchAll();
        if(!empty($data))
            return $data;
    }

    public function getUserByInviter($uid)
    {
        $data = $this->getORM()->where(['inviterid' => $uid])->where('uid != 0')->select('uid')->fetchAll();
        return $data;
    }

    public function getUserForDetail($id)
    {
        $sql = 'SELECT u.u_pic '
            . 'FROM byb_user AS u  LEFT JOIN byb_eleven_user AS w '
            . 'ON u.id = w.inviterid '
            . 'WHERE w.inviterid = ? and w.uid != 0 and u.login_time != 0';

        $data = $this->getORM()->queryRows($sql, [$id]);
        return $data;
    }

    public function getByPhone($phone)
    {
        $data = $this->getORM()->where(['telphone' => $phone])->fetchOne();
        return $data;
    }

}